package com.sg.business.model.dataset.work;

import com.mongodb.BasicDBObject;
import com.sg.business.model.Deliverable;
import com.sg.business.model.IModelConstants;
import com.sg.business.model.IWorkRelative;
import com.sg.business.model.Work;
import com.sg.widgets.commons.dataset.MasterDetailDataSetFactory;

public class RelatitedWorkReferenceDeliveryDataSet extends
		MasterDetailDataSetFactory {

	public RelatitedWorkReferenceDeliveryDataSet() {
		super(IModelConstants.DB, IModelConstants.C_DELIEVERABLE);
		setQueryCondition(new BasicDBObject().append(Deliverable.F_TYPE,
				Deliverable.TYPE_REFERENCE));
	}

	@Override
	protected String getDetailCollectionKey() {
		return Deliverable.F_WORK_ID;
	}

	@Override
	protected Object getMasterValue() {
		if (master instanceof Work) {
			return master.get_id();
		} else if (master instanceof IWorkRelative) {
			return ((IWorkRelative) master).getWork().get_id();
		}
		return null;
	}
}
